<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品属性列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input id="mid" name="mid" th:value="${mid}" type="hidden">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <label>规格名称：</label>
                                <input type="text" name="attributeName"/>
                            </li>
                            <!--<li>
                                <label>统一批发价 配件店：</label>
                                <input type="text" name="attributeWholesalePrice"/>
                            </li>
                            <li>
                                <label>统一零售价 维修师傅：</label>
                                <input type="text" name="attributeRetailPrice"/>
                            </li>
                            <li>
                                <label>排序 排序数字越大，排序约靠前：</label>
                                <input type="text" name="attributeSort"/>
                            </li>
                            <li>
                                <label>配件id：</label>
                                <input type="text" name="partsId"/>
                            </li>-->
                            <li>
                                <label>是否上架：</label>
                                <select name="isShow" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <!--<li>
                                <label>运费：</label>
                                <input type="text" name="attributeShippingFee"/>
                            </li>
                            <li>
                                <label>偏远地区的运费：</label>
                                <input type="text" name="attributeShippingFeeremote"/>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:sellPartsAttribute:add">
                    <i class="fa fa-plus"></i> 添加新规格
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:sellPartsAttribute:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:sellPartsAttribute:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:sellPartsAttribute:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:sellPartsAttribute:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:sellPartsAttribute:remove')}]];
        var isShowDatas = [[${@dict.getType('zsyh_yesno')}]];
        var prefix = ctx + "zsyh/sellPartsAttribute";

        $(function() {
            var options = {
                url: prefix + "/listDetail?partsId="+$("#mid").val(),
                createUrl: prefix + "/add/"+$("#mid").val(),
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "产品属性",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '产品属性',
                    visible: false
                },
                {
                    field: 'attributeName',
                    align: 'center',
                    title: '属性名称'
                },
                {
                    field: 'attributeLogo',
                    align: 'center',
                    title: '属性logo',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'attributeWholesalePrice',
                    align: 'center',
                    title: '统一批发价'
                },
                {
                    field: 'attributeRetailPrice',
                    align: 'center',
                    title: '统一零售价'
                },
                {
                    field: 'attributeSort',
                    align: 'center',
                    title: '排序'
                },
                {
                    field: 'attributeRemarks',
                    align: 'center',
                    title: '属性备注'
                },
                /*{
                    field: 'partsId',
                    title: '配件id'
                },*/
                {
                    field: 'isShow',
                    align: 'center',
                    title: '是否上架',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowDatas, value);
                    }
                },
                {
                    field: 'attributeShippingFee',
                    align: 'center',
                    title: '运费'
                },
                {
                    field: 'attributeShippingFeeremote',
                    align: 'center',
                    title: '偏远地区的运费'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(index !=0){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" style="background: purple;border-color: purple" href="javascript:void(0)" onclick="moveTop(\'' + row.id + '\')"><i class="fa fa-edit"></i>置顶</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" style="background: #f18112;border-color: #f18112" href="javascript:void(0)" onclick="moveUp(\'' + row.id + '\',\''+index+'\')"><i class="fa fa-remove"></i>上移</a>');
                        }
                        actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" style="margin-left: 3px;background: #1d9caa;border-color: #1d9caa" href="javascript:void(0)" onclick="moveDown(\'' + row.id + '\',\''+index+'\')"><i class="fa fa-remove"></i>下移</a>');
                        actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" style="margin-left: 3px;background: #aa3424;border-color: #aa3424" href="javascript:void(0)" onclick="moveChange(\'' + row.partsId + '\',\''+row.id+'\')"><i class="fa fa-remove"></i>移动到指定规格之后</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function moveTop(id) {
            $.modal.confirm("确认要置顶该规格吗？", function() {
                $.operate.post(prefix + "/moveTop", { "id":id});
            })
        }

        function moveDown(id,index) {
            debugger;
            var otherIndex = Number(index)+1;
            var otherData = $("#bootstrap-table").bootstrapTable('getData')[otherIndex];
            if(otherData != undefined){
                var currentData = $("#bootstrap-table").bootstrapTable('getData')[index];
                var upId = otherData.id;
                $.modal.confirm("确认要移动该规格吗？", function() {
                    $.operate.post(prefix + "/moveUp", { "id":id,"otherId":upId,"attributeSort":currentData.attributeSort,"otherAttributeSort":otherData.attributeSort});
                })
            }else{
                $.modal.alertWarning("当前页中最后一个不能下移");
            }
        }

        function moveUp(id,index) {
            var otherData = $("#bootstrap-table").bootstrapTable('getData')[index-1];
            var currentData = $("#bootstrap-table").bootstrapTable('getData')[index];
            var upId = otherData.id;
            $.modal.confirm("确认要移动该规格吗？", function() {
                $.operate.post(prefix + "/moveUp", { "id":id,"otherId":upId,"attributeSort":currentData.attributeSort,"otherAttributeSort":otherData.attributeSort});
            })
        }

        function moveChange(partsId,oldId) {
            var url = prefix + "/moveChange/"+partsId+"/"+oldId;
            layer.open({
                type: 2,
                area: ['800px', '500px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "指定产品规格",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

    </script>
</body>
</html>